package com.ruoyi.syf.controller;

import java.util.Arrays;
import java.util.List;

import com.ruoyi.syf.domain.vo.RiskMeasureVo;
import com.ruoyi.syf.handler.deleteChain.DeleteService;
import com.ruoyi.syf.service.IRiskMeasureService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 管控措施
 *
 * @author yr
 * @date 2024-07-04
 */
@RestController
@RequestMapping("/syf/measure")
public class RiskMeasureController extends BaseController {
    @Autowired
    private IRiskMeasureService riskMeasureService;
    @Autowired
    private DeleteService deleteService;

    /**
     * 查询管控措施列表
     */
    @GetMapping("/list")
    public TableDataInfo list(RiskMeasureVo vo) {
        startPage();
        List<RiskMeasureVo> list = riskMeasureService.list(vo);
        return getDataTable(list);
    }

    /**
     * 获取管控措施详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(riskMeasureService.selectRiskMeasureById(id));
    }

    /**
     * 新增管控措施
     */
    @PreAuthorize("@ss.hasPermi('syf:measure:add')")
    @Log(title = "管控措施", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RiskMeasureVo vo) {
        return toAjax(riskMeasureService.insertRiskMeasure(vo));
    }

    /**
     * 修改管控措施
     */
    @PreAuthorize("@ss.hasPermi('syf:measure:edit')")
    @Log(title = "管控措施", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RiskMeasureVo vo) {
        return toAjax(riskMeasureService.updateRiskMeasure(vo));
    }

    /**
     * 删除管控措施
     */
    @PreAuthorize("@ss.hasPermi('syf:measure:remove')")
    @Log(title = "管控措施", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        deleteService.deleteMeasure(Arrays.asList(ids));
        return toAjax(true);
    }
}
